<?php
/**
 * 项目：红河移动工程现场管理系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Event_model extends CI_Model {
   function __construct()
    {
        parent::__construct();
    }
   function setEvent($event,$module,$isAdmin){
     $id="";
     $event=substr($event,0,40);
     $user= mysql_real_escape_string(trim($this->session->userdata('ppms_admin_auth')));
     if($user!=""):
      $this->db->where('login',$user);
      $this->db->select('uid,name');
      $query = $this->db->get("members");
      foreach ($query->result() as $row){ $id=$row->uid;$name=$row->name;}
      $this->load->library('user_agent');
      //当User Agent 类初始化后，它会判断浏览你的网站是Web浏览器，还是移动设备，还是机器人。它还收集相关的操作系统信息
      if ($this->agent->is_browser())
      {
       $agent = $this->agent->browser().' '.$this->agent->version();
      }
      elseif ($this->agent->is_robot())
     {
       $agent = $this->agent->robot();
     }
     elseif ($this->agent->is_mobile())
     {
       $agent = $this->agent->mobile();
     }
      else
     {
      $agent = 'Unidentified User Agent';
     }
     //end agent
     $insert_data=array(
               'uid' => "{$id}" ,
               'name' => "{$name}" ,
               'ev_event' => "{$event}",
               'ev_ip' => "{$_SERVER['REMOTE_ADDR']}",
                'ev_module' => "{$module}",
                'ev_platform' => $this->agent->platform(),
                'ev_browser' => $this->agent->browser(),
                'ev_agent' =>  $agent,
                'ev_isadmin' => $isAdmin,
            );
      $this->db->set('ev_time','NOW()',false);         
      $this->db->insert("event",$insert_data);
      return $this->db->affected_rows();
   endif;
   }
 function setEventMain($event,$module,$isAdmin){
     $id="";
     $user= mysql_real_escape_string(trim($this->session->userdata('ppms_username_auth_main')));
     if($user!=""):
      $this->db->where('login',$user);
      $this->db->select('uid,name');
      $query = $this->db->get("members");
      foreach ($query->result() as $row){ $id=$row->uid;$name=$row->name;
      }
      $this->load->library('user_agent');
      //当User Agent 类初始化后，它会判断浏览你的网站是Web浏览器，还是移动设备，还是机器人。它还收集相关的操作系统信息
      if ($this->agent->is_browser())
      {
       $agent = $this->agent->browser().' '.$this->agent->version();
      }
      elseif ($this->agent->is_robot())
     {
       $agent = $this->agent->robot();
     }
     elseif ($this->agent->is_mobile())
     {
       $agent = $this->agent->mobile();
     }
      else
     {
      $agent = 'Unidentified User Agent';
     }
     //end agent
     $insert_data=array(
               'uid' => "{$id}" ,
               'name' => "{$name}" ,
               'ev_event' => "{$event}",
               'ev_ip' => "{$_SERVER['REMOTE_ADDR']}",
                'ev_module' => "{$module}",
                'ev_platform' => $this->agent->platform(),
                'ev_browser' => $this->agent->browser(),
                'ev_agent' =>  $agent,
                'ev_isadmin' => $isAdmin,
            );
      $this->db->set('ev_time','NOW()',false);         
      $this->db->insert("event",$insert_data);
      return $this->db->affected_rows();
   endif;
   }
    function setEventMainOfNoLogin($event,$module,$isAdmin){
      $this->load->library('user_agent');
      //当User Agent 类初始化后，它会判断浏览你的网站是Web浏览器，还是移动设备，还是机器人。它还收集相关的操作系统信息
      if ($this->agent->is_browser())
      {
       $agent = $this->agent->browser().' '.$this->agent->version();
      }
      elseif ($this->agent->is_robot())
     {
       $agent = $this->agent->robot();
     }
     elseif ($this->agent->is_mobile())
     {
       $agent = $this->agent->mobile();
     }
      else
     {
      $agent = 'Unidentified User Agent';
     }
     //end agent
     $insert_data=array(
               'ev_event' => "{$event}",
               'ev_ip' => "{$_SERVER['REMOTE_ADDR']}",
                'ev_module' => "{$module}",
                'ev_platform' => $this->agent->platform(),
                'ev_browser' => $this->agent->browser(),
                'ev_agent' =>  $agent,
                'ev_isadmin' => $isAdmin,
            );
      $this->db->set('ev_time','NOW()',false);         
      $this->db->insert("event",$insert_data);
      return $this->db->affected_rows();
    }
}